home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / pc / tutorial / ch08_lgo / tutor.dcr / 00003_pseudo html.ls < prev    next >
Encoding:
Text File  |  1996-12-06  |  6.8 KB  |  240 lines

  1. global gLinkList, gLinkCursor, gVisited, gLinkInfo, gVisitedLinkColor, gNextLink, gLinkHiColor, gLoSprite, gHiSprite, gFreshLinkColor
  2.  
  3. on initPseudoHTML
  4.   set gLinkCursor to [201, 202]
  5.   set gVisited to []
  6.   set the itemDelimiter to ","
  7.   set gLinkInfo to [#destination: EMPTY, #defaultColor: 0, #visited: 0]
  8.   set gVisitedLinkColor to 177
  9.   set gLinkHiColor to 250
  10. end
  11.  
  12. on mouseDown
  13.   set gNextLink to isLink()
  14.   if not gNextLink then
  15.     pass()
  16.   else
  17.     colorLinkText(gLinkHiColor)
  18.   end if
  19. end
  20.  
  21. on mouseUp
  22.   if gNextLink then
  23.     goToLink(gLinkInfo)
  24.   end if
  25.   pass()
  26. end
  27.  
  28. on idle
  29.   checkRollN(gLoSprite, gHiSprite)
  30.   set linkHandle to isLink()
  31.   if not linkHandle then
  32.     cursor(-1)
  33.   else
  34.     cursor(gLinkCursor)
  35.   end if
  36. end
  37.  
  38. on isLink
  39.   global oldCast, oldChar, lastLink, linkVal
  40.   if the mouseCast > 0 then
  41.     set mCast to the mouseCast
  42.     set mChar to the mouseChar
  43.     if the mouseChar < 0 then
  44.       set linkVal to 0
  45.     else
  46.       set cCast to getCurrLabel() & "Links"
  47.       if the number of member cCast <> -1 then
  48.         if (mCast <> oldCast) or (oldChar <> mChar) then
  49.           repeat with x = 1 to the number of lines in field cCast
  50.             if integer(item 1 of line x of field cCast) = mCast then
  51.               if not (mChar < integer(item 2 of line x of field cCast)) and not (mChar > integer(item 3 of line x of field cCast)) then
  52.                 set gLinkInfo to linkInfo(line x of field cCast)
  53.                 set linkVal to 1
  54.                 set oldCast to mCast
  55.                 set oldChar to mChar
  56.                 return linkVal
  57.                 exit
  58.               end if
  59.             end if
  60.           end repeat
  61.           set linkVal to 0
  62.           set oldCast to mCast
  63.           set oldChar to mChar
  64.           return linkVal
  65.           exit
  66.         else
  67.           return linkVal
  68.           exit
  69.         end if
  70.       else
  71.         set linkVal to 0
  72.       end if
  73.     end if
  74.   else
  75.     set linkVal to 0
  76.   end if
  77.   set oldCast to 0
  78.   set oldChar to 0
  79.   return linkVal
  80. end
  81.  
  82. on goToLink theLink
  83.   colorLinkText(gVisitedLinkColor)
  84.   set linkDest to getaProp(gLinkInfo, #destination)
  85.   if linkDest contains ".htm" then
  86.     go(1, linkDest)
  87.   else
  88.     if linkDest contains ".dcr" then
  89.       GoToNetMovie(linkDest)
  90.     else
  91.       go(linkDest)
  92.     end if
  93.   end if
  94. end
  95.  
  96. on makeLink destination
  97.   if the selection = 0 then
  98.     put "You must hilite some text"
  99.     exit
  100.   end if
  101.   if the number of member (getCurrLabel() & "Links") = -1 then
  102.     makeLinkContainer(getCurrLabel())
  103.   end if
  104.   repeat with i = 1 to 48
  105.     if the castNum of sprite i then
  106.       if the castType of cast the castNum of sprite i = #text then
  107.         set linkStart to offset(the selection, the text of field the castNum of sprite i)
  108.         if linkStart then
  109.           set linkCast to the castNum of sprite i
  110.           exit repeat
  111.         end if
  112.       end if
  113.     end if
  114.   end repeat
  115.   set unColor to the foreColor of char linkStart of member linkCast
  116.   set visited to "0"
  117.   set linkLine to linkCast & "," & linkStart & "," & the selEnd & "," & destination & "," & unColor & "," & visited & "," & string(0)
  118.   saveLinkProps(getCurrLabel(), linkLine)
  119. end
  120.  
  121. on refreshLinks clearing
  122.   set cCast to getCurrLabel() & "Links"
  123.   if the number of member cCast <> -1 then
  124.     repeat with x = 1 to the number of lines in field cCast
  125.       set linkStuff to linkInfo(line x of field cCast)
  126.       if listp(linkStuff) then
  127.         if clearing = 1 then
  128.           setaProp(linkStuff, #visited, 0)
  129.           put "0" into item 6 of line x of field cCast
  130.         end if
  131.         if getaProp(linkStuff, #visited) = 1 then
  132.           set linkColor to gVisitedLinkColor
  133.         else
  134.           set linkColor to getaProp(linkStuff, #defaultColor)
  135.         end if
  136.         set the foreColor of char getaProp(linkStuff, #headChar) to getaProp(linkStuff, #tailChar) of member getaProp(linkStuff, #linkCast) to linkColor
  137.       end if
  138.     end repeat
  139.     updateStage()
  140.   end if
  141. end
  142.  
  143. on colorLinkText theColor, theLink
  144.   if not theLink then
  145.     set theLink to gLinkInfo
  146.   end if
  147.   set the foreColor of char getaProp(theLink, #headChar) to getaProp(theLink, #tailChar) of member getaProp(theLink, #linkCast) to theColor
  148.   updateStage()
  149. end
  150.  
  151. on linkInfo theLine
  152.   set oldDelim to the itemDelimiter
  153.   set the itemDelimiter to ","
  154.   if the number of items in theLine < 6 then
  155.     set rVal to -1
  156.   else
  157.     set lCast to integer(item 1 of theLine)
  158.     set tStart to integer(item 2 of theLine)
  159.     set tEnd to integer(item 3 of theLine)
  160.     set dest to item 4 of theLine
  161.     set defColor to integer(item 5 of theLine)
  162.     set visitBool to integer(item 6 of theLine)
  163.     if not integerp(lCast) or not integerp(tStart) or not integerp(tEnd) or not stringp(dest) or not integerp(defColor) or not integerp(visitBool) then
  164.       set rVal to -1
  165.     end if
  166.   end if
  167.   if not rVal then
  168.     set rVal to [#linkCast: lCast, #headChar: tStart, #tailChar: tEnd, #destination: dest, #defaultColor: defColor, #visited: visitBool]
  169.   else
  170.     set rVal to 0
  171.   end if
  172.   return rVal
  173.   set the itemDelimiter to oldDelim
  174. end
  175.  
  176. on saveLinkProps linkLabel, linkData
  177.   set oldDelim to the itemDelimiter
  178.   set the itemDelimiter to ","
  179.   set linkCast to linkLabel & "Links"
  180.   if the number of member linkCast = -1 then
  181.     makeLinkContainer(linkLabel)
  182.   end if
  183.   if listp(linkData) then
  184.   else
  185.     if stringp(linkData) then
  186.       set thisIndex to integer(the last item in linkData)
  187.     end if
  188.   end if
  189.   set newIndex to numLinks(linkLabel) + 1
  190.   if not thisIndex then
  191.     delete item 6 of linkData
  192.     put "," & string(newIndex) after linkData
  193.     put linkData & RETURN after field linkCast
  194.   else
  195.     put linkData into line newIndex of field linkCast
  196.   end if
  197.   set the itemDelimiter to oldDelim
  198. end
  199.  
  200. on numLinks theLabel
  201.   set oldDelim to the itemDelimiter
  202.   set the itemDelimiter to ","
  203.   set theCast to theLabel & "Links"
  204.   set rVal to 0
  205.   if the number of member theCast <> -1 then
  206.     repeat with i = 1 to the number of lines in field theCast
  207.       if integer(the last item in line i of field theCast) > rVal then
  208.         set rVal to integer(the last item in line i of field theCast)
  209.       end if
  210.     end repeat
  211.   end if
  212.   return rVal
  213.   set the itemDelimiter to oldDelim
  214. end
  215.  
  216. on linkLine theLabel, theIndex
  217.   set oldDelim to the itemDelimiter
  218.   set the itemDelimiter to ","
  219.   set theCast to theLabel & "Links"
  220.   set rVal to 0
  221.   if the number of member theCast <> -1 then
  222.     repeat with i = 1 to the number of lines in field theCast
  223.       if integer(the last item in line i of field theCast) = theIndex then
  224.         set rVal to i
  225.         exit repeat
  226.       end if
  227.     end repeat
  228.   end if
  229.   return rVal
  230.   set the itemDelimiter to oldDelim
  231. end
  232.  
  233. on makeLinkContainer theLabel
  234.   repeat with k = the number of member "startLinks" to the number of castMembers
  235.     if (the name of cast k = 0) and (the castType of cast k = #text) then
  236.       set the name of cast k to theLabel & "Links"
  237.     end if
  238.   end repeat
  239. end
  240.